//
//  ZDBActivityHeadView.m
//  ZDB
//
//  Created by Kk on 2020/3/19.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBActivityHeadView.h"

@implementation ZDBActivityHeadView

-(void)awakeFromNib{
    [super awakeFromNib];
   
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(6, 6)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    _bgView.layer.mask = maskLayer;
    KViewRadius(self.sign_Monday, 4);
    KViewRadius(self.sign_Tuesday, 4);
    KViewRadius(self.sign_Wednesday, 4);
    KViewRadius(self.sign_Thursday, 4);
    KViewRadius(self.sign_Friday, 4);
    KViewRadius(self.sign_Saturday, 4);
    KViewRadius(self.sign_Sunday, 4);
    [self.sign_Monday setBackgroundColor:ColorStr(@"#f3f3f2") forState:(UIControlStateNormal)];
    [self.sign_Tuesday setBackgroundColor:ColorStr(@"#f3f3f2") forState:(UIControlStateNormal)];
    [self.sign_Wednesday setBackgroundColor:ColorStr(@"#f3f3f2") forState:(UIControlStateNormal)];
    [self.sign_Thursday setBackgroundColor:ColorStr(@"#f3f3f2") forState:(UIControlStateNormal)];
    [self.sign_Friday setBackgroundColor:ColorStr(@"#f3f3f2") forState:(UIControlStateNormal)];
    [self.sign_Saturday setBackgroundColor:ColorStr(@"#f3f3f2") forState:(UIControlStateNormal)];
    [self.sign_Sunday setBackgroundColor:ColorStr(@"#f3f3f2") forState:(UIControlStateNormal)];
    
    [self.sign_Monday setBackgroundColor:ColorStr(@"#fef2cf") forState:(UIControlStateSelected)];
    [self.sign_Tuesday setBackgroundColor:ColorStr(@"#fef2cf") forState:(UIControlStateSelected)];
    [self.sign_Wednesday setBackgroundColor:ColorStr(@"#fef2cf") forState:(UIControlStateSelected)];
    [self.sign_Thursday setBackgroundColor:ColorStr(@"#fef2cf") forState:(UIControlStateSelected)];
    [self.sign_Friday setBackgroundColor:ColorStr(@"#fef2cf") forState:(UIControlStateSelected)];
    [self.sign_Saturday setBackgroundColor:ColorStr(@"#fef2cf") forState:(UIControlStateSelected)];
    [self.sign_Sunday setBackgroundColor:ColorStr(@"#fef2cf") forState:(UIControlStateSelected)];
    self.totalLab.unit =  @"分";
    self.totalLab.prefix =  @"积分余额：";
    self.totalLab.format= @"%.2f";
    self.totalLab.method = UILabelCountingMethodEaseOut;
    
    self.SignDayValue.unit = @"天";
    self.SignDayValue.format= @"%0.0f";
    self.SignDayValue.prefix= @"已签到天数";
    self.SignDayValue.method = UILabelCountingMethodEaseOut;
   
    
    

    _buttons = [NSMutableArray new];
    _labs = [NSMutableArray new];
    [_buttons addObject:self.sign_Monday];
    [_buttons addObject:self.sign_Tuesday];
    [_buttons addObject:self.sign_Wednesday];
    [_buttons addObject:self.sign_Thursday];
    [_buttons addObject:self.sign_Friday];
    [_buttons addObject:self.sign_Saturday];
    [_buttons addObject:self.sign_Sunday];
    
    [_labs addObject:_lab1];
    [_labs addObject:_lab2];
    [_labs addObject:_lab3];
    [_labs addObject:_lab4];
    [_labs addObject:_lab5];
    [_labs addObject:_lab6];
    [_labs addObject:_lab7];
   
    [_severBtn add_BtnClickHandler:^(NSInteger tag) {
        if (![ZBDUnit getLoginJurisdiction]) {
               return;
           }
        ZDContactUsBViewController * chatVC = [ZDContactUsBViewController new];
        chatVC.title = @"联系我们";
        [[ZBDUnit currentViewController].navigationController pushViewController:chatVC animated:YES];
        
    }];
    
}
- (void)LogOutSusess
{
    
    for (UIButton * button in _buttons)
    {
        [button setTitle:@"已签" forState:(UIControlStateSelected)];
        [button setTitle:@"未签" forState:(UIControlStateNormal)];
        button.userInteractionEnabled = NO;
        button.selected = NO;
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
        [button setTitleEdgeInsets:UIEdgeInsetsMake(button.imageView.height+10 ,-button.imageView.width, 0.0,0.0)];
        [button setImageEdgeInsets:UIEdgeInsetsMake(-16, 0.0,0.0, -button.titleLabel.bounds.size.width)];

    }
    
}
- (void)getSignInfoList:(NSArray *)signInfoList
{
    for (int i =0; i<signInfoList.count; i++) {
        NSDictionary * dic = signInfoList[i];
        UIButton * button = _buttons[i];
        UILabel * lable = _labs[i];
        lable.text = kFormat(@"%@", dic[@"integral"]);
        [button setTitle:@"已签" forState:(UIControlStateSelected)];
        [button setTitle:@"未签" forState:(UIControlStateNormal)];
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
        [button setTitleEdgeInsets:UIEdgeInsetsMake(button.imageView.height+10 ,-button.imageView.width, 0.0,0.0)];
        [button setImageEdgeInsets:UIEdgeInsetsMake(-16, 0.0,0.0, -button.titleLabel.bounds.size.width)];
        button.userInteractionEnabled = NO;
        button.selected = NO;
        
    }
    
}
- (void)getSignCont:(NSInteger)signCont wihtIsTodaySign:(NSInteger)isTodaySign signInfoList:(NSArray *)signInfoList //今日是否签到
{
    _signCont = signCont;
      
    [self getSignInfoList:signInfoList];
    for (NSInteger i= 0; i< signCont-1; i++)
    {
        UIButton * button = _buttons[i];
        button.selected = YES;
    }
    if (isTodaySign==1) {

          UIButton * button = _buttons[signCont-1];
          [button setTitle:@"今日" forState:0];
          button.selected = NO;
          button.userInteractionEnabled = YES;
          
      }else
      {
         UIButton * button = (signCont>1)? _buttons[signCont-2]:_buttons[signCont-1];
         button.selected = YES;
         [button setTitle:@"今日" forState:(UIControlStateSelected)];
         button.userInteractionEnabled = NO;
         
      }
     [self.SignDayValue  countFrom:0 to:_signCont-1 withDuration:1];
}
//- (void)LogOutSusess
//{
//
//    for (UIButton * button in _buttons)
//    {
//        button.userInteractionEnabled = NO;
//        button.selected = NO;
//        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
//        [button setTitleEdgeInsets:UIEdgeInsetsMake(button.imageView.height+10 ,-button.imageView.width, 0.0,0.0)];
//        [button setImageEdgeInsets:UIEdgeInsetsMake(-16, 0.0,0.0, -button.titleLabel.bounds.size.width)];
//
//    }
//}
//- (void)getSignInfoList:(NSArray *)signInfoList
//{
//    for (int i =0; i<signInfoList.count; i++) {
//        NSDictionary * dic = signInfoList[i];
//        UIButton * button = _buttons[i];
//        UILabel * lable = _labs[i];
//        lable.text = kFormat(@"%@", dic[@"integral"]);
//        button.userInteractionEnabled = NO;
//        button.selected = NO;
//
//    }
//
//}
//- (void)getSignCont:(NSInteger)signCont wihtIsTodaySign:(NSInteger)isTodaySign signInfoList:(NSArray *)signInfoList //今日是否签到
//{
//    _signCont = signCont;
//
//    [self getSignInfoList:signInfoList];
//
//
//
//    if (isTodaySign==1) {
//
//          UIButton * button = _buttons[signCont-1];
//          [button setTitle:@"今日" forState:0];
//          button.selected = NO;
//          button.userInteractionEnabled = YES;
//
//      }else
//      {
//          for (UIButton * btn in _buttons) {
//            [btn setTitle:@"已签" forState:(UIControlStateSelected)];
//            btn.selected = NO;
//          }
//
//          UIButton * button = (signCont>1)? _buttons[signCont-2]:_buttons[signCont-1];
//         button.selected = YES;
//         [button setTitle:@"今日" forState:(UIControlStateSelected)];
//         button.userInteractionEnabled = NO;
//
//
//
//      }
//
//
//    if (isTodaySign==1) {
//     // isTodaySign 1 未签到 signCont 1 今天签到第一天
//
//        for (NSInteger i= 0; i< signCont-1; i++)
//          {
//              UIButton * button = _buttons[i];
//              button.selected = YES;
//          }
//
//    }else{
//        for (NSInteger i= 0; i< signCont-2; i++)
//          {
//              UIButton * button = _buttons[i];
//              button.selected = YES;
//          }
//
//    }
//    ////isTodaySign 今日是否签到 1未签到 2已签到    signCont 今天签到第几天
//
//    [self.SignDayValue  countFrom:0 to:_signCont-1 withDuration:1];
//}

- (IBAction)sender:(UIButton *)sender {
    
    if (![ZBDUnit getLoginJurisdiction]) {
        return;
    }
    if (self.signInblock) {
        self.signInblock(sender);
    }
   
}
@end
